package com.yanqu.road.server.gameplayer.module.charitable;

import com.yanqu.road.entity.config.charitable.CharitableSpecialEvent;
import com.yanqu.road.entity.config.charitable.CharitableWordConfig;
import com.yanqu.road.entity.config.charitable.CharitableWorkConsumeConfig;
import com.yanqu.road.entity.config.goods.OpenGoodsBagResult;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.config.skill.SkillUpgradeInfo;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.player.*;
import com.yanqu.road.logic.bussiness.player.UserCharitableBusiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.activity.RecoveryRewardProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.gameplayer.module.travel.TravelModule;
import com.yanqu.road.server.manger.config.CharitableWorkMgr;
import com.yanqu.road.server.manger.config.GoodsBagMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.rank.RankMgr;
import com.yanqu.road.server.pb.CharitablePb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.*;

/**
 * @Author wpj
 * @Date 2020/8/30
 */
public class CharitableModule extends GeneralModule {

    Map<Integer, UserCharitablePosition> userCharitablePositionMap;
    UserCharitable userCharitable;
    Map<Integer, Map<Integer, UserCharitableSkill>> positionSkillMap;

    public Map<Integer, UserCharitablePosition> getUserCharitablePositionMap() {
        return userCharitablePositionMap;
    }

    public UserCharitable getUserCharitable() {
        return userCharitable;
    }

    public Map<Integer, Map<Integer, UserCharitableSkill>> getPositionSkillMap() {
        return positionSkillMap;
    }

    public CharitableModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        userCharitable = UserCharitableBusiness.getUserCharitable(player.getUserId());
        userCharitablePositionMap = UserCharitableBusiness.getUserCharitablePositionMap(player.getUserId());
        positionSkillMap = UserCharitableBusiness.getUserCharitableSkillMap(player.getUserId());

        if (SystemOpenMgr.systemOpen(player, eSystemId.Charitable.getValue())) {
            initData();
        }
        return true;
    }


    /**
     * 每日重置
     */
    public void resetOneDay() {
        if (SystemOpenMgr.systemOpen(player, eSystemId.Charitable.getValue())) {
            reset();
            player.sendPacket(ClientProtocol.U_CHARITABLE_WORK_DATA, CharitablePb.getCharitableDataMsg(userCharitable, userCharitablePositionMap, positionSkillMap));
        }
    }

    /**
     * 初始化系统数据
     */
    public void initSystem() {
        initData();
        // 没有数据则不发送
        reset();
        if (userCharitable.getCharitableType() <= 0) {
            newRandomCharitableWork();
        }
        // 发送数据
        player.sendPacket(ClientProtocol.U_CHARITABLE_WORK_DATA, CharitablePb.getCharitableDataMsg(userCharitable, userCharitablePositionMap, positionSkillMap));
    }

    /**
     * 初始化并检查数据
     */
    public void initData() {
        if (userCharitable == null) {
            UserCharitable newUserCharitable = new UserCharitable();
            newUserCharitable.setUserId(player.getUserId());
            newUserCharitable.setCharitableType(0);
            newUserCharitable.setResetTime(0);
            newUserCharitable.setTodayCharitableTimes(0);
            newUserCharitable.setAllCostMoney(BigInteger.ZERO);
            newUserCharitable.setInsertOption();
            userCharitable = newUserCharitable;
        }

        for (CharitableWordConfig charitableWordConfig : CharitableWorkMgr.getCharitableWordConfigMap().values()) {

            // 初始化行善地点
            if (!userCharitablePositionMap.containsKey(charitableWordConfig.getType())) {
                UserCharitablePosition userCharitablePosition = new UserCharitablePosition();
                userCharitablePosition.setUserId(player.getUserId());
                userCharitablePosition.setCharitableForUpgradeTimes(0);
                userCharitablePosition.setType(charitableWordConfig.getType());
                userCharitablePosition.setInsertOption();
                userCharitablePositionMap.put(userCharitablePosition.getType(), userCharitablePosition);
            }

            // 初始化技能
            if (!positionSkillMap.containsKey(charitableWordConfig.getType())) {
                positionSkillMap.put(charitableWordConfig.getType(), new HashMap<>());
            }
            for (int skillId : charitableWordConfig.getSkills()) {
                if (!positionSkillMap.get(charitableWordConfig.getType()).containsKey(skillId)) {
                    UserCharitableSkill userCharitableSkill = new UserCharitableSkill();
                    userCharitableSkill.setUserId(player.getUserId());
                    userCharitableSkill.setPosition(charitableWordConfig.getType());
                    userCharitableSkill.setSkillId(skillId);
                    userCharitableSkill.setLevel(1);
                    userCharitableSkill.setInsertOption();
                    positionSkillMap.get(charitableWordConfig.getType()).put(skillId, userCharitableSkill);
                }
            }
        }
    }

    /**
     * 重置
     */
    public void reset() {
        if (!DateHelper.isToday(new Date(userCharitable.getResetTime()))) {
            userCharitable.setTodayCharitableTimes(1);
            userCharitable.setResetTime(System.currentTimeMillis());
            userCharitable.setInSystem(false);
            if (userCharitable.getCharitableType() == 0) {
                int randomNum = new Random().nextInt(CharitableWorkMgr.getCharitableWordConfigMap().size());
                userCharitable.setCharitableType(new ArrayList<>(CharitableWorkMgr.getCharitableWordConfigMap().values()).get(randomNum).getType());
            }
        }
    }

    /**
     * 随机一个新行善
     */
    public void newRandomCharitableWork() {
        int randomNum = new Random().nextInt(CharitableWorkMgr.getCharitableWordConfigMap().size());
        userCharitable.setCharitableType(new ArrayList<>(CharitableWorkMgr.getCharitableWordConfigMap().values()).get(randomNum).getType());
        userCharitable.setTodayCharitableTimes(userCharitable.getTodayCharitableTimes() + 1);
    }

    @Override
    public boolean afterLoadData() {
        if (SystemOpenMgr.systemOpen(player, eSystemId.Charitable.getValue())) {
            initData();
        }
        return true;
    }

    @Override
    public boolean saveData() {
        if (userCharitable != null) {
            if (userCharitable.isInsertOption()) {
                UserCharitableBusiness.addUserCharitable(userCharitable);
            } else if (userCharitable.isUpdateOption()) {
                UserCharitableBusiness.updateUserCharitable(userCharitable);
            }
        }

        for (UserCharitablePosition userCharitablePosition : userCharitablePositionMap.values()) {
            if (userCharitablePosition.isInsertOption()) {
                UserCharitableBusiness.addUserCharitablePosition(userCharitablePosition);
            } else if (userCharitablePosition.isUpdateOption()) {
                UserCharitableBusiness.updateUserCharitablePosition(userCharitablePosition);
            }
        }

        for (Map<Integer, UserCharitableSkill> userCharitableSkillMap : positionSkillMap.values()) {
            for (UserCharitableSkill userCharitableSkill : userCharitableSkillMap.values()) {
                if (userCharitableSkill.isInsertOption()) {
                    UserCharitableBusiness.addUserCharitableSkill(userCharitableSkill);
                } else if (userCharitableSkill.isUpdateOption()) {
                    UserCharitableBusiness.updateUserCharitableSkill(userCharitableSkill);
                }
            }
        }

        return true;
    }

    @Override
    public void afterLogin() {
        if (SystemOpenMgr.systemOpen(player, eSystemId.Charitable.getValue())) {
            initSystem();
        }
    }

    /**
     * 行善
     */
    public CharitableDoOneTimeResult doCharitable() {
        // 判断是否有随机出类型
        if (userCharitable.getCharitableType() <= 0) {
            return new CharitableDoOneTimeResult(GameErrorCode.E_CHARITABLE_NOT_RANDOM_POSITION);
        }

        // 判断次数是否已满
        CharitableWorkConsumeConfig charitableWorkConsumeConfig = CharitableWorkMgr.getCharitableWorkConsumeConfigMap().get(userCharitable.getTodayCharitableTimes() + 1);
        if (charitableWorkConsumeConfig == null) {
            return new CharitableDoOneTimeResult(GameErrorCode.E_CHARITABLE_TIMES_FULL);
        }


        // 取消耗的银两并且判断银两
        String cost = CharitableWorkMgr.getCharitableWorkConsumeConfigMap().get(userCharitable.getTodayCharitableTimes()).getConsume();
        CurrencyModule currencyModule = player.getModule(CurrencyModule.class);
        if (!currencyModule.removeCurrency(PropertyHelper.parseStringToProperty(cost), eLogMoneyType.Charitable, eLogMoneyType.CharitableDo)) {
            return new CharitableDoOneTimeResult(GameErrorCode.E_BAG_SILVER_NO_ENOUGH);
        }

        // 增加行善地点的行善次数
        UserCharitablePosition userCharitablePosition = userCharitablePositionMap.get(userCharitable.getCharitableType());
        userCharitablePosition.setCharitableForUpgradeTimes(userCharitablePosition.getCharitableForUpgradeTimes() + 1);

        // 组装返回值
        CharitableDoOneTimeResult charitableDoOneTimeResult = new CharitableDoOneTimeResult(doCharitableLogic(player.getModule(BeautyModule.class)));
        charitableDoOneTimeResult.setCharitableType(userCharitable.getCharitableType());
        charitableDoOneTimeResult.setTodayCharitableTimes(userCharitable.getTodayCharitableTimes());
        charitableDoOneTimeResult.setCharitableForUpgradeTimes(userCharitablePosition.getCharitableForUpgradeTimes());

        setCostMoney(PropertyHelper.parseStringToProperty(cost));
        // 修改榜单
        changeCharitableRank();

        // 任务通知
        player.notifyListener(eGamePlayerEventType.CharitableTotalTimes.getValue());
        player.notifyListener(eGamePlayerEventType.CharitableTimes.getValue(), 1);
        log.info("Charitable One. userId : {}, cost:{}", player.getUserId(), cost);
        return charitableDoOneTimeResult;
    }

    /**
     * 改变榜单
     */
    public void changeCharitableRank() {
        try {
            RankMgr.changeUserRank(eBigRankType.Normal.getValue(), player.getUserId(), userCharitable.getAllCostMoney(), eRankType.Charitable.getValue(), "");
        } catch (Exception ex) {
            log.error(ex);
        }
    }

    /**
     * 执行行善的基本逻辑
     *
     * @param beautyModule
     * @return
     */
    public CharitableDoLogicResult doCharitableLogic(BeautyModule beautyModule) {
        // 随机绣房以外的美女一名
        UserBeauty userBeauty = beautyModule.getRandomBeauty();

        CharitableWordConfig charitableWordConfig = CharitableWorkMgr.getCharitableWordConfigMap().get(userCharitable.getCharitableType());
        // 计算奖励的魅力值 增加魅力值
        List<Integer> glamourAddList = charitableWordConfig.getGlamourAddList();
        int addValue = glamourAddList.get((userCharitable.getTodayCharitableTimes() - 1) % glamourAddList.size());
        beautyModule.addGlamour(userBeauty, addValue, eLogMoneyType.Charitable.getValue(), eLogMoneyType.CharitableDo.getValue());
        beautyModule.syncUserBeauty(userBeauty);

        // 取宝箱并且打开箱子获得奖励
        int boxId = charitableWordConfig.getRewardBoxList().get((userCharitable.getTodayCharitableTimes() - 1) % charitableWordConfig.getRewardBoxList().size());
        OpenGoodsBagResult openGoodsBagResult = GoodsBagMgr.getRandomGoods(boxId);
        CurrencyModule currencyModule = player.getModule(CurrencyModule.class);
        currencyModule.addCurrency(openGoodsBagResult.getReward(), eLogMoneyType.Charitable, eLogMoneyType.CharitableDo);

        // 触发特殊事件
        // 取行善地点的配置 TODO 第一次的按配置来..暂时没配置
        CharitableSpecialEvent charitableSpecialEvent = CharitableWorkMgr.getRandomSpecialEvent(charitableWordConfig.getSpecialGuideList(), userCharitable.getTodayCharitableTimes() == 1 ? true : false);
        if (eCharitableSpecialEventRewardType.Power == charitableSpecialEvent.getRewardType()) {
            player.getModule(TravelModule.class).addPower(charitableSpecialEvent.getRewardNum());
        } else if (eCharitableSpecialEventRewardType.Energy == charitableSpecialEvent.getRewardType()) {
            player.getModule(BeautyModule.class).recoverEnergy(charitableSpecialEvent.getRewardNum());
        }

        CharitableDoLogicResult charitableDoLogicResult = new CharitableDoLogicResult();
        if(userBeauty != null){
            charitableDoLogicResult.setBeautyId(userBeauty.getBeautyId());
            charitableDoLogicResult.setGlamourAddValue(addValue);
        }
        charitableDoLogicResult.setBoxReward(PropertyHelper.parsePropertyToString(openGoodsBagResult.getReward()));
        charitableDoLogicResult.setEvent(charitableSpecialEvent);
        charitableDoLogicResult.setPositionType(userCharitable.getCharitableType());

        // 重新生成一个行善地点
        newRandomCharitableWork();

        return charitableDoLogicResult;
    }

    /**
     * 10次行善
     *
     * @return
     */
    public CharitableDoTenTimeResult doCharitableTen(int times) {
        // 判断是否有随机出类型
        if (times <= 0) {
            return new CharitableDoTenTimeResult(GameErrorCode.E_CHARITABLE_TIMES_ERROR);
        }
        if (userCharitable.getCharitableType() <= 0) {
            return new CharitableDoTenTimeResult(GameErrorCode.E_CHARITABLE_NOT_RANDOM_POSITION);
        }
        // 判断银两足够几次行善
        CurrencyModule currencyModule = player.getModule(CurrencyModule.class);
        Map<Integer, CharitableWorkConsumeConfig> charitableWorkConsumeConfigMap = CharitableWorkMgr.getCharitableWorkConsumeConfigMap();
        Property allCost = new Property();
        int realTimes = 0;
        boolean full = false;
        for (int i = 0; i < times; i++) {
            Property cost = new Property();
            cost.addProperty(allCost);

            CharitableWorkConsumeConfig charitableWorkConsumeConfig = charitableWorkConsumeConfigMap.get(userCharitable.getTodayCharitableTimes() + i);
            if (charitableWorkConsumeConfig == null) {
                full = true;
                break;
            }

            cost.addProperty(PropertyHelper.parseStringToProperty(charitableWorkConsumeConfig.getConsume()));
            if (!currencyModule.currencyIsEnough(cost)) {
                break;
            }
            allCost.addProperty(PropertyHelper.parseStringToProperty(charitableWorkConsumeConfigMap.get(userCharitable.getTodayCharitableTimes() + i).getConsume()));
            realTimes++;
        }

        // 次数为0则提示银两不足
        if (realTimes == 0) {
            if (full) {
                // 当次数满
                return new CharitableDoTenTimeResult(GameErrorCode.E_CHARITABLE_TIMES_FULL);
            }
            return new CharitableDoTenTimeResult(GameErrorCode.E_BAG_SILVER_NO_ENOUGH);
        }

        // 扣除银两
        currencyModule.removeCurrency(allCost, eLogMoneyType.Charitable, eLogMoneyType.CharitableDoTen);

        // 随机美女
        BeautyModule beautyModule = player.getModule(BeautyModule.class);
        List<CharitableDoLogicResult> list = new ArrayList<>();
        for (int i = 0; i < realTimes; i++) {
            UserCharitablePosition userCharitablePosition = userCharitablePositionMap.get(userCharitable.getCharitableType());
            userCharitablePosition.setCharitableForUpgradeTimes(userCharitablePosition.getCharitableForUpgradeTimes() + 1);
            list.add(doCharitableLogic(beautyModule));
        }

        // 组装返回值
        CharitableDoTenTimeResult charitableDoTenTimeResult = new CharitableDoTenTimeResult(list);
        charitableDoTenTimeResult.setRet(0);
        charitableDoTenTimeResult.setCharitableType(userCharitable.getCharitableType());
        charitableDoTenTimeResult.setTodayCharitableTimes(userCharitable.getTodayCharitableTimes());
        Map<Integer, Integer> map = new HashMap<>();
        for (UserCharitablePosition userCharitablePosition : userCharitablePositionMap.values()) {
            map.put(userCharitablePosition.getType(), userCharitablePosition.getCharitableForUpgradeTimes());
        }
        charitableDoTenTimeResult.setAllPositionCharitableTimesMap(map);

        setCostMoney(allCost);
        // 修改榜单
        changeCharitableRank();

        // 任务通知
        player.notifyListener(eGamePlayerEventType.CharitableTotalTimes.getValue());
        player.notifyListener(eGamePlayerEventType.CharitableTimes.getValue(), realTimes);

        log.info("Charitable Ten. userId : {}, times : {}, cost:{}", player.getUserId(), realTimes, PropertyHelper.parsePropertyToString(allCost));
        return charitableDoTenTimeResult;
    }

    /**
     * 升级行善地点
     *
     * @param position
     */
    public ReturnData upgradeSkill(int position, int skillId) {
        // 判断行善地点
        UserCharitablePosition userCharitablePosition = userCharitablePositionMap.get(position);
        if (userCharitablePosition == null) {
            return new ReturnData(GameErrorCode.E_CHARITABLE_NOT_THIS_POSITION, 0 + "");
        }

        // 判断行善技能
        UserCharitableSkill userCharitableSkill = positionSkillMap.get(position).get(skillId);
        if (userCharitableSkill == null) {
            return new ReturnData(GameErrorCode.E_CHARITABLE_SKILL_NOT_FOUND, 0 + "");
        }

        // 判断技能配置
        SkillInfo skillInfo = SkillMgr.getSkillInfo(skillId);
        if (skillInfo == null) {
            return new ReturnData(GameErrorCode.E_CHARITABLE_SKILL_NOT_FOUND, userCharitableSkill.getLevel() + "");
        }

        // 判断升级配置
        SkillUpgradeInfo nextUpgradeInfo = SkillMgr.getSkillUpgradeInfo(skillInfo.getUpgradeType(0), userCharitableSkill.getLevel() + 1);
        if (null == nextUpgradeInfo) {
            return new ReturnData(GameErrorCode.E_BEAUTY_LEVEL_MAX, userCharitableSkill.getLevel() + "");
        }

        // 判断升级的消耗是否足够
        SkillUpgradeInfo consume = SkillMgr.getSkillUpgradeInfo(skillInfo.getUpgradeType(0), userCharitableSkill.getLevel());
        if (consume == null) {
            return new ReturnData(GameErrorCode.E_CHARITABLE_SKILL_LEVEL_MAX, userCharitableSkill.getLevel() + "");
        }
        long needConsume = consume.getConsumeCount();
        if (userCharitablePosition.getCharitableForUpgradeTimes() < needConsume) {
            return new ReturnData(GameErrorCode.E_CHARITABLE_TIMES_NOT_ENOUGH, userCharitableSkill.getLevel() + "");
        }

        // 修改等级
        userCharitableSkill.setLevel(userCharitableSkill.getLevel() + 1);

        log.info("Charitable upgrade skill. userId : {}, skillId: {}, newLevel : {}, cost:{}", player.getUserId(), skillInfo.getId(), userCharitableSkill.getLevel(), needConsume);

        return new ReturnData(0, userCharitableSkill.getLevel() + "");
    }

    public void setCostMoney(Property cost) {
         BigInteger costMoney = cost.getCountByGoodsId(GameConfig.GAME_MONEY_SILVER);
         userCharitable.setAllCostMoney(userCharitable.getAllCostMoney().add(costMoney));

    }

    /**
     * 设置进入系统的状态
     */
    public void setInSystem() {
        if (userCharitable != null) {
            userCharitable.setInSystem(true);
        }
    }

    /**
     * 获取对应职业的加成值
     * @param occupationType
     * @return
     */
    public int getAddChildValue(int occupationType) {
        int addValue = 0;
        for (Map<Integer, UserCharitableSkill> userCharitableSkillMap : positionSkillMap.values()) {
            for (UserCharitableSkill userCharitableSkill : userCharitableSkillMap.values()) {
                SkillInfo skillInfo = SkillMgr.getSkillInfo(userCharitableSkill.getSkillId());
                if (skillInfo == null) {
                    log.error("skill is null. skillId : {}", userCharitableSkill.getSkillId());
                    continue;
                }
                if (skillInfo.getParamList().get(2) == occupationType && skillInfo.getType() == eSkillType.AddChildAbility.getValue()) {
                    addValue = addValue + SkillMgr.getSkillAddition(skillInfo, userCharitableSkill.getLevel());
                }
            }
        }
        return addValue;
    }

    public CharitableDoTenTimeResult recoveryCharitable(int days, int discount, RecoveryRewardProto.RecoveryRewardMsg.Builder builder) {
        if (days <= 0) {
            return new CharitableDoTenTimeResult(GameErrorCode.E_CHARITABLE_TIMES_ERROR);
        }
        if (userCharitable.getCharitableType() <= 0) {
            return new CharitableDoTenTimeResult(GameErrorCode.E_CHARITABLE_NOT_RANDOM_POSITION);
        }
        BigInteger sliverLimit = player.getUserInfo().getEarnSpeed().multiply(BigInteger.valueOf(43200L));//12h 客户端写死的 我们也写死吧

        Map<Integer, CharitableWorkConsumeConfig> workConsumeConfigMap = CharitableWorkMgr.getCharitableWorkConsumeConfigMap();
        Property totalNeed = new Property();
        CurrencyModule currencyModule = player.getModule(CurrencyModule.class);
        int oneDayTime = 0;
        for (; oneDayTime < workConsumeConfigMap.size(); ) {
            CharitableWorkConsumeConfig charitableWorkConsumeConfig = workConsumeConfigMap.get(oneDayTime + 1);
            if (charitableWorkConsumeConfig == null) {
                break;
            }
            Property onceNeed = PropertyHelper.parseStringToProperty(charitableWorkConsumeConfig.getConsume());
            totalNeed.addProperty(onceNeed);
            if (totalNeed.getCountByGoodsId(GameConfig.GAME_MONEY_SILVER).compareTo(sliverLimit) > 0) {
                break;
            }
            oneDayTime++;
        }

        int oneDayRecoveryTime = oneDayTime * discount / 1000;

        Property realNeed = new Property();
        for (int i = 1;i <= oneDayRecoveryTime;i++){
            CharitableWorkConsumeConfig charitableWorkConsumeConfig = workConsumeConfigMap.get(i);
            if (charitableWorkConsumeConfig == null) {
                break;
            }
            Property onceNeed = PropertyHelper.parseStringToProperty(charitableWorkConsumeConfig.getConsume());
            realNeed.addProperty(onceNeed);
        }

        int allRecoveryTime = oneDayRecoveryTime * days;
        //先算总需求
        realNeed.goodCountMultiNum(days);
        if (currencyModule.currencyIsEnough(realNeed)) {
            currencyModule.removeCurrency(realNeed, eLogMoneyType.RecoveryReward, eLogMoneyType.RecoveryCharitableCost);
        } else {
            BigInteger silver = player.getModule(PlayerModule.class).getUserInfo().getSilver();
            Property hasSliver = new Property(GameConfig.GAME_MONEY_SILVER, silver);
            if (!currencyModule.removeCurrency(hasSliver, eLogMoneyType.RecoveryReward, eLogMoneyType.RecoveryCharitableCost)) {
                log.error("玩家{}找回行善时银两不够并且扣除失败", getUserId());
            }
        }
        //先reset 不然会炸
        reset();
        // 随机美女
        BeautyModule beautyModule = player.getModule(BeautyModule.class);
        List<CharitableDoLogicResult> list = new ArrayList<>();
        for (int i = 0; i < allRecoveryTime; i++) {
            UserCharitablePosition userCharitablePosition = userCharitablePositionMap.get(userCharitable.getCharitableType());
            userCharitablePosition.setCharitableForUpgradeTimes(userCharitablePosition.getCharitableForUpgradeTimes() + 1);
            list.add(doCharitableLogic(beautyModule));
        }
        // 组装返回值
        CharitableDoTenTimeResult charitableDoTenTimeResult = new CharitableDoTenTimeResult(list);
        charitableDoTenTimeResult.setRet(0);
        charitableDoTenTimeResult.setCharitableType(2);
        charitableDoTenTimeResult.setTodayCharitableTimes(userCharitable.getTodayCharitableTimes());
        Map<Integer, Integer> map = new HashMap<>();
        for (UserCharitablePosition userCharitablePosition : userCharitablePositionMap.values()) {
            map.put(userCharitablePosition.getType(), userCharitablePosition.getCharitableForUpgradeTimes());
        }
        charitableDoTenTimeResult.setAllPositionCharitableTimesMap(map);
        // 修改榜单
        changeCharitableRank();
        //重置
        userCharitable.setTodayCharitableTimes(1);
        // 任务通知
        player.notifyListener(eGamePlayerEventType.CharitableTotalTimes.getValue());
        builder.setCharitableNeedSliver(PropertyHelper.parsePropertyToString(realNeed));
        return charitableDoTenTimeResult;

    }


}
